import jieba
import pickle
from typing import List
import csv

str1 = jieba.cut_for_search("小明硕士毕业于中国科学院计算所，后在日本京都大学深造,小明硕士毕业于中国科学院计算所，后在日本京都大学深造")  # 搜索引擎模式
ID1 = 1
str2 = jieba.cut_for_search("我来到北京清华大学")  # 搜索引擎模式
ID2 = 2

dic1 = {}
keyWord = open("wordSeg.csv", 'a', encoding='gbk')
writer = csv.writer(keyWord)
for x in str1:
    if dic1.get(x):
        continue
    else:
        dic1[x] = [ID1]

for x in str2:
    if dic1.get(x):
        dic1[x].append(ID2)
    else:
        dic1[x] = [ID2]
keys = list(dic1.keys())
values = list(dic1.values())
for x in range(len(dic1)):
    a = [keys[x]]
    for y in values[x]:
        a.append(y)
    writer.writerow(a)
    print(keys[x], values[x])

# with open('data.pickle', 'wb') as f:
#     pickle.dump(dic1, f)
